package cn.j0n4than.api.controller.api.admin;

import cn.j0n4than.api.entity.User;
import cn.j0n4than.api.entity.pojo.UserAddPojo;
import cn.j0n4than.api.service.UserService;
import cn.j0n4than.api.utils.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/admin/user")
public class AdminUserController {

    @Autowired
    UserService userService;

    @PostMapping("/add")
    public Response add(@RequestBody UserAddPojo userAddPojo) {
        Response response = Response.response();
        User user = new User();
        user.username = userAddPojo.username;
        user.email = userAddPojo.email;
        user.password = userAddPojo.password;
        if (userService.insert(user) > 0) {
            response.setStatus(200).setMessage("添加用户成功");
        } else {
            response.setStatus(500).setMessage("添加用户失败");
        }

        return response;
    }
}
